package com.lqian.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.lqian.pojo.Employee;
import com.lqian.utils.PageUtil;

public interface EmployeeMapper {


	@Select("select * from employee")
	List<Employee> getAllEmployee(); 


	/**
	 * user login
	 */
	@Select("select employee.*,depart.dname from employee inner join depart on employee.eid = depart.did where ename = #{ename} and epass = #{epass}")
	Employee login(@Param("ename")String ename,@Param("epass")String epass);


	/**
	 * update password
	 */
	@Update("update employee set epass = #{epass} where eid = #{eid}")
	void updatePwd(@Param("epass")String epass,@Param("eid")Integer eid);


	/**
	 * select myinfo
	 */
	Employee getEmployeeWithDept(Integer eideid);

	/**
	 * 全查询显示员工信息
	 */
	@Select("select * from employee INNER join depart on employee.did = depart.did")
	List<Employee> getEmployeeDept(); 



	/**
	 * 查询所以的记录行条数
	 */
	@Select("select count(*) from employee")
	Integer count(); 



	//分页查询  返回值 是集合  参数：pageUtil对象
	@Select("select * from employee inner join depart on employee.did=depart.did limit #{start},#{pageSize}")
	List<Employee> findAllEmpByPage(PageUtil page);


	/**
	 * 通过eid查找员工
	 * @param eid
	 * @return
	 */
	@Select("select * from employee where eid=#{eid}")
	Employee findUserByEid(@Param("eid") Integer eid);
	
	/**
	 * 更新用户
	 * @param emp
	 * @return
	 */
	@Update("update employee set realname=#{realname},ename=#{ename},epass=#{epass},esex=#{esex},did=#{did},position=#{position} where eid=#{eid}")
	Integer updateUser(Employee emp);
	
	/**
	 * 逻辑删除用户
	 * @param did
	 * @return
	 */
	@Update("update employee set estatus = 1 where eid=#{eid}")
	Integer deleteEmployee(@Param("eid")Integer eid);

	/**
	 * 逻辑恢复用户
	 * @param did
	 * @return
	 */
	@Update("update employee set estatus=0 where eid=#{eid}")
	Integer resEmployee(@Param("eid")Integer eid);

	
	
	/**
	 * 添加用户
	 * @param employee
	 * @return
	 */
	@Insert("INSERT INTO employee"
			+ "(eid,ename,epass,realname,esex,entrydate,position,sal,estatus,did) "
			+ "values(NULL,#{ename},#{epass},#{realname},#{esex},now(),#{position},#{sal},#{estatus},#{did})")
	Integer addEmployee(Employee employee);


}